package apis

import (
	"github.com/gin-gonic/gin"
	"fmt"
	"hulk-api/models"
	"net/http"
)

func HandleLogin(c *gin.Context) {
	var u models.User
	c.BindJSON(&u)

	//account := c.Request.FormValue("username")
	//passWord := c.Request.FormValue("password")
	//u := models.User{Account:account,Password:passWord}
	fmt.Println("uuu is,",u)
	user,err := u.GetUser()
	if err != nil {
		fmt.Println("error is",err)
	}

	if user.Account == "" {
		c.JSON(http.StatusOK,gin.H{
			"code": 400,
			"msg": "用户名或密码错误",
		})
	} else {
		go user.UpdateUserLoginDatetime()
		c.JSON(http.StatusOK,gin.H{
			"user": user,
			"code": 200,
		})
	}
}

